#include<iostream>
#include<algorithm>

using namespace std;

const int N = 1e6 + 10;

int n;

struct node
{
	int l, r;
}a[N];

bool cmp(node& x, node& y)
{
	return x.l < y.l;
}

int main()
{
	cin >> n;
	
	for (int i = 1; i <= n; i++)
		cin >> a[i].l >> a[i].r;
	
	sort(a + 1, a + 1 + n, cmp);

	int ret = 1;
	int r = a[1].r;
	
	for (int i = 2; i <= n; i++)
	{
		int right = a[i].r, left = a[i].l;
		if (left < r) r = min(r, right);
		else ret++, r = right;
	}
	
	cout << ret << endl;
	
	return 0;
}